import aixos from 'axios'
import { jsonp } from '@/assets/js/jsonp.js'
import { options } from './config'
export const getBannerInfo = () => { // 获取banner数据
  return aixos.get('http://www.imooc.com/api/home/slider', { timeout: 3000 })
    .then(res => {
      if (res.data.code === 0) {
        return res.data.slider
      }
      throw new Error('未能获取到数据')
    }).catch(err => {
      console.log(err)
      return [{ picUrl: require('@/assets/img/404.png'), linkUrl: null }]
    })
}
export const getRecommendInfo = (page = 1, psize = 20) => { // 获取recommend数据
  const url = 'https://ju.taobao.com/json/tg/ajaxGetItemsV2.json'
  const params = {
    page,
    psize,
    type: 0,
    frontCatId: ''
  }
  return jsonp(url, options, params).then(res => {
    if (res) {
      return res
    }
    throw new Error('未能获取到数据')
  }).catch(err => {
    console.log(err)
  })
}
